﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Alkitab.Language;
using System.Windows.Navigation;

namespace Alkitab.View
{
    public partial class Options : PhoneApplicationPage
    {
        private bool[] settingX = { false, false, false, false, false };

        private List<int> temp = new List<int>();

        public Options()
        {
            InitializeComponent();

            // for misc setting page
            for (int i = 0; i < 5; i++)
            {
                if ((((String)Globals.Settingan["parallelRead"])[i]).Equals('1')) settingX[i] = true;
            }
            ITB.IsChecked = settingX[0];
            BSH.IsChecked = settingX[1];
            MLB.IsChecked = settingX[2];
            ASV.IsChecked = settingX[3];
            KJV.IsChecked = settingX[4];
            mazmurSwitch.IsChecked = (bool)Globals.Settingan["mazmurOn?"];

            // for ukuran font page
            loremipsum.FontSize = (int)Globals.Settingan["fontsize?"];
            informasi.Text = returnTextCurrentFontSize();
            for (int i = 15; i <= 40; i++)
            {
                temp.Add(i);
            }
            fontSize.ItemsSource = temp;
            if ((((int)Globals.Settingan["fontsize?"]) >= 15) & (((int)Globals.Settingan["fontsize?"]) <= 40)) fontSize.SelectedIndex = (int)Globals.Settingan["fontsize?"] - 15;
            fontSize.ScrollIntoView(fontSize.SelectedItem);

            if (!Globals.Settingan.Contains("infoOptionsDisplayed?"))
            {
                MessageBoxResult result = MessageBox.Show(Labels.informationOption, Labels.information, MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    Globals.Settingan.Add("infoOptionsDisplayed?", 1);
                }
            }
        }

        #region pivotJump
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string strItemIndex;
            if (NavigationContext.QueryString.TryGetValue("Page", out strItemIndex))
                ThePivot.SelectedIndex = Convert.ToInt32(strItemIndex) - 1;

            base.OnNavigatedTo(e);
        }
        #endregion pivotJump

        #region gantiBahasa
        private void gantiEnglish_Click(object sender, RoutedEventArgs e)
        {
            Globals.changeLanguageK(2);
            MessageBoxResult m = MessageBox.Show(Labels.MSG_LangChanged);
            Globals.Settingan["languagek?"] = 2;
            Pilihan.needRefresh = true;
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiGerman_Click(object sender, RoutedEventArgs e)
        {
            Globals.changeLanguageK(3);
            MessageBoxResult m = MessageBox.Show(Labels.MSG_LangChanged);
            Globals.Settingan["languagek?"] = 3;
            Pilihan.needRefresh = true;
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiIndo_Click(object sender, RoutedEventArgs e)
        {
            Globals.changeLanguageK(1);
            MessageBoxResult m = MessageBox.Show(Labels.MSG_LangChanged);
            Globals.Settingan["languagek?"] = 1;
            Pilihan.needRefresh = true;
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }
        #endregion gantiBahasa

        #region gantiTerjemahan
        private void gantiASV_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["versiKitab"] = "AmericanStandardVersion";
            Globals.versiKitab = "AmericanStandardVersion";
            Globals.Settingan["parallelRead"] = "00001";
            Bacaan.needRefresh = true;
            MessageBoxResult m = MessageBox.Show(Labels.MSG_NowUse + " 'American Standard Version'.");
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiIndonesiaSeharihari_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["versiKitab"] = "IndonesiaSeharihari";
            Globals.versiKitab = "IndonesiaSeharihari";
            Globals.Settingan["parallelRead"] = "10000";
            Bacaan.needRefresh = true;
            MessageBoxResult m = MessageBox.Show(Labels.MSG_NowUse + " 'Bahasa Indonesia Sehari-hari'.");
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiKJV_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["versiKitab"] = "KingJamesVersion";
            Globals.versiKitab = "KingJamesVersion";
            Globals.Settingan["parallelRead"] = "00010";
            Bacaan.needRefresh = true;
            MessageBoxResult m = MessageBox.Show(Labels.MSG_NowUse + " 'King James Version'.");
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiLuther_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["versiKitab"] = "GermanvLuther";
            Globals.versiKitab = "GermanvLuther";
            Globals.Settingan["parallelRead"] = "00001";
            Bacaan.needRefresh = true;
            MessageBoxResult m = MessageBox.Show(Labels.MSG_NowUse + " 'Luther'.");
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }

        private void gantiTerjemahanBaru_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["versiKitab"] = "TerjemahanBaru";
            Globals.versiKitab = "TerjemahanBaru";
            Globals.Settingan["parallelRead"] = "01000";
            Bacaan.needRefresh = true;
            MessageBoxResult m = MessageBox.Show(Labels.MSG_NowUse + " 'Indonesia Terjemahan Baru'.");
            if (m == MessageBoxResult.OK) this.NavigationService.GoBack();
        }
        #endregion gantiTerjemahan

        #region miscSettingPage

        private void MazmurSwitch_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["mazmurOn?"] = (bool)mazmurSwitch.IsChecked;
        }

        private void TranslationSwitch_Click(object sender, RoutedEventArgs e)
        {
            settingX[0] = (bool)ITB.IsChecked;
            settingX[1] = (bool)BSH.IsChecked;
            settingX[2] = (bool)MLB.IsChecked;
            settingX[3] = (bool)ASV.IsChecked;
            settingX[4] = (bool)KJV.IsChecked;
            String temp = "";
            for (int i = 0; i < 5; i++)
            {
                if (settingX[i]) temp += "1"; else temp += "0";
            }
            Globals.Settingan["parallelRead"] = temp;
        }

        #endregion miscSettingPage

        #region ukuranFontPage

        private void fontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!(fontSize.SelectedIndex == -1)) Globals.Settingan["fontsize?"] = fontSize.SelectedItem;
            loremipsum.FontSize = (int)Globals.Settingan["fontsize?"];
            informasi.Text = returnTextCurrentFontSize();
        }

        private string returnTextCurrentFontSize()
        {
            return (Labels.currentFontSize + (int)Globals.Settingan["fontsize?"]);
        }

        private void standard_Click(object sender, RoutedEventArgs e)
        {
            Globals.Settingan["fontsize?"] = 23;
            fontSize.SelectedIndex = (int)Globals.Settingan["fontsize?"] - 15;
            fontSize.ScrollIntoView(fontSize.SelectedItem);
            MessageBox.Show(Labels.MSG_StandardFontSize);
        }

        #endregion ukuranFontPage
    }
}